<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	template="../index.xhtml">
	
	<h:head>
		<f:facet name="first">
			<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
			<title>Leitos</title>
		</f:facet>
		
		<f:metadata>
			<f:event type="preRenderView" listener="#{ringController.getRingController}" />
		</f:metadata>
		
	</h:head>

	<ui:define name="content">

		<center>
			<h:form id="form">

				<p:panel style="height:95%;width:95%"
					header="HOSPITAL UNIVERSITÁRIO LAURO WANDERLEY - UNIDADE DE TERAPIA INTENSIVA NEONATAL">

					<p:panel id="panelLeitos" style="height:95%;width:95%"
						header="Gerenciamento de Leitos" widgetVar="infoLeito"
						visible="true" effect="fade" closable="true" closeSpeed="0">

						<c:if test="#{ringController.vazio == true}">
							<f:verbatim>
								<br />
							</f:verbatim>
							<h:outputText
								value="Os Leitos estão desocupados!" rendered="#{sec:areAllGranted('ROLE_TEC')}"/>
						</c:if>
									
						<c:forEach items="#{ringController.leitos}" var="leito">

							<c:choose>
								<c:when test="#{(leito.id &lt; 4)}">
									<c:choose>
										<c:when test="#{(leito.paciente != null)}">
											<p:commandButton id="carBtn#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;">
											</p:commandButton>
										</c:when>
										<c:otherwise>
											<p:commandButton id="carBtn#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;background:none;color:black;"
												oncomplete="infoLeito.close(); "
												rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
											<p:commandButton id="carBtn1#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;background:none;color:black;"
												oncomplete="infoLeito.close(); "
												rendered="#{sec:areAllGranted('ROLE_ENF')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
										</c:otherwise>
									</c:choose>

									<c:if test="#{(leito.paciente != null)}">
										<p:overlayPanel id="carPanel#{leito.id}"
											for="carBtn#{leito.id}" hideEffect="fade">

											<h:outputText
												value="Leito ocupado por #{leito.paciente.nome} 
												desde  #{leito.paciente.data_admissao} #{leito.paciente.hora_admissao}" />

											<br />

											<p:commandButton id="ver#{leito.id}" value="Verificar dados"
												oncomplete="carPanel#{leito.id}.hide()">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
											<p:commandButton id="des#{leito.id}" value="Desocupar Leito"
												oncomplete="carPanel#{leito.id}.hide()" rendered="#{sec:areAllGranted('ROLE_ENF')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.desocupiedLeito}" />
											</p:commandButton>
											<p:commandButton id="des1#{leito.id}" value="Desocupar Leito"
												oncomplete="carPanel#{leito.id}.hide()" rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.desocupiedLeito}" />
											</p:commandButton>

										</p:overlayPanel>
									</c:if>


									<c:if test="#{(leito.id == 3)}">
										<f:verbatim>
											<br />
										</f:verbatim>
									</c:if>
								</c:when>
								<c:otherwise>
									<c:choose>
										<c:when test="#{(leito.paciente != null)}">
											<p:commandButton id="carBtn#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;">
											</p:commandButton>
										</c:when>
										<c:otherwise>
											<p:commandButton id="carBtn#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;background:none;color:black;"
												rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
											<p:commandButton id="carBtn2#{leito.id}"
												value="LEITO #{leito.id}"
												style="margin:60px;width:100px;height:50px;background:none;color:black;"
												rendered="#{sec:areAllGranted('ROLE_ENF')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
										</c:otherwise>
									</c:choose>




									<c:if test="#{(leito.paciente != null)}">
										<p:overlayPanel id="carPanel#{leito.id}"
											for="carBtn#{leito.id}" hideEffect="fade">

											<h:outputText
												value="Leito ocupado por #{leito.paciente.nome} 
												desde  #{leito.paciente.data_admissao} #{leito.paciente.hora_admissao}" />

											<br />

											<p:commandButton id="ver#{leito.id}" value="Verificar dados"
												oncomplete="carPanel#{leito.id}.hide()">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.selectedLeito}" />
											</p:commandButton>
											<p:commandButton id="des#{leito.id}" value="Desocupar Leito"
												oncomplete="carPanel#{leito.id}.hide()" rendered="#{sec:areAllGranted('ROLE_ENF')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.desocupiedLeito}" />
											</p:commandButton>
											<p:commandButton id="des2#{leito.id}" value="Desocupar Leito"
												oncomplete="carPanel#{leito.id}.hide()" rendered="#{sec:areAllGranted('ROLE_ADMIN')}">
												<f:setPropertyActionListener value="#{leito.id}"
													target="#{ringController.desocupiedLeito}" />
											</p:commandButton>

										</p:overlayPanel>
									</c:if>


								</c:otherwise>
							</c:choose>

						</c:forEach>


					</p:panel>

				</p:panel>

			</h:form>

		</center>
	</ui:define>
</ui:composition>